package com.fjb.controller.user;


import java.time.LocalDateTime;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.fjb.common.entity.HttpCode;
import com.fjb.common.entity.JsonResult;
import com.fjb.common.entity.JsonTotalResult;
import com.fjb.common.entity.PageQuery;
import com.fjb.controller.base.BaseController;
import com.fjb.pojo.banner.BannerInfo;
import com.fjb.pojo.login.LoginUserInfo;
import com.fjb.pojo.user.SysUser;
import com.fjb.service.user.SysUserService;

/**
 * <p>
 * 用户信息 前端控制器
 * </p>
 *
 * @author hemiao
 * @since 2019-12-22
 */
@Controller
@RequestMapping("/sysUser")
public class SysUserController extends BaseController{
	
	@Autowired
    private SysUserService sysUserService;
    
    /**
     * @Description:用户分页列表
     * @param request
     * @return
     * ModelAndView
     * @exception:
     * @author: hemiao
     * @time:2019年5月4日 下午3:51:28
     */
    @RequestMapping(value="/showPageList")
    public ModelAndView showPageList(HttpServletRequest request) {
    	ModelAndView mv = new ModelAndView();	
    	mv.setViewName("/user/sys_user_list");
    	return mv;
    }
    
    /**
     * @Description:分页列表查询
     * @param request
     * @param pageInfoQuery
     * @return
     * JsonTotalResult<List<SysUser>>
     * @exception:
     * @author: hemiao
     * @time:2019年5月4日 下午3:51:41
     */
    @RequestMapping(value = "/selectPageList")
    @ResponseBody
    public JsonTotalResult<List<SysUser>> selectPageList(HttpServletRequest request, PageQuery pageQuery){
        SysUser sysUser = new SysUser();
        LoginUserInfo userInfo = getUserInfo(request);
        Integer mainUserId = userInfo.getSysUser().getMainUserId();
        Integer userType = userInfo.getSysUser().getUserType();
        sysUser.setUserType(userType);	
        sysUser.setMainUserId(mainUserId);
    	return sysUserService.selectPageList(sysUser,pageQuery);
    }
	
    /**
     * @Description:修改用户状态
     * @param request
     * @param userId
     * @param userStatus
     * @return
     * JsonResult<Boolean>
     * @exception:
     * @author: hemiao
     * @time:2020年3月2日 下午8:27:00
     */
    @RequestMapping(value = "/updateStatus")
    @ResponseBody
    public JsonResult<Boolean> updateStatus(HttpServletRequest request,Integer userId,Integer userStatus){
		HttpCode httpCode = HttpCode.PARAM_VERIFICATION;
		if(userId==null||userStatus==null) {	
			return new JsonResult<Boolean>(null, httpCode);
		}
		LoginUserInfo userInfo = getUserInfo(request);
		SysUser sysUser = userInfo.getSysUser();
		Integer cUserId = sysUser.getId();
		
		SysUser su = new SysUser();
		su.setId(userId);
		su.setUserStatus(userStatus);
		su.setUpdateUserId(cUserId);
		su.setUpdateTime(LocalDateTime.now());
		boolean b = sysUserService.updateById(su);
		return new JsonResult<Boolean>(b, HttpCode.SUCCESS);
	}
}
